package com.hexus.eve.entities.security;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name="groups")
public class SecurityGroup {
	@Id 
	@GeneratedValue
	private Integer id;
	
	@Column(name="group_name")
	private String name;
	
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name="group_members", joinColumns={@JoinColumn(name="group_id")}, inverseJoinColumns={@JoinColumn(name="username")})
	private List<User> users = new ArrayList<User>();
	
	@CollectionOfElements
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "group_authorities", joinColumns = @JoinColumn(name = "group_id"))
	@Column(name="authority", nullable=false)
	private Set<String> authorities = new HashSet<String>();

	public Set<String> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<String> authorities) {
		this.authorities = authorities;
	}

	public List<User> getUsers() {
		return users;
	}

	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
}
